﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LayoutPlanning.CollaborationService;
using Mvvm;

namespace LayoutPlanning.ViewModel
{
    public class ProjectViewModel:ViewModelBase
    {

        

        public ProjectViewModel(ProjectArea project)
        {
            if(project == null)
                project = new ProjectArea();
            Project = project;
            
        }

        public string Name
        {
            get { return Project.ProjectAreaName; }
            set
            {
                if(value == Project.ProjectAreaName)
                    return;
                
#if DEBUG
                var service = new CollaborationService.ServiceContractClient("BasicHttpsBinding_IServiceContractDebug");
#else
                    var service = new  CollaborationService.ServiceContractClient("BasicHttpsBinding_IServiceContract");
#endif
                service.DeleteProject(Project.ProjectAreaName, Project.LayoutName);
                Project.ProjectAreaName = value;
                ViewModelLocator.Main.SaveAreaCommand.Execute(null);
                
                RaisePropertyChanged();

            }
        }


        public ProjectArea Project { get; }
        public double PosX
        {
            get { return Project.ProjectAreaDef.X; }
            set
            {
                Project.ProjectAreaDef = new Rectangle((int)value, (int)PosY, (int)SizeY, (int)SizeY);
                RaisePropertyChanged();
                
            }
        }
        
        public double PosY
        {
            get { return Project.ProjectAreaDef.Y; }
            set
            {
                Project.ProjectAreaDef = new Rectangle((int)PosX, (int)value, (int)SizeY, (int)SizeY);
                RaisePropertyChanged();

            }
        }
        public double SizeX
        {
            get { return Project.ProjectAreaDef.Width; }
            set
            {
                Project.ProjectAreaDef = new Rectangle((int)PosX, (int)PosY, (int)value, (int)SizeY);
                RaisePropertyChanged();

            }
        }
        public double SizeY
        {
            get { return Project.ProjectAreaDef.Height; }
            set
            {
                Project.ProjectAreaDef = new Rectangle((int)PosX, (int)PosY, (int)SizeX, (int)value);
                RaisePropertyChanged();

            }
        }
    }
}
